/**
 * Created by lizhe on 2018/4/18.
 */
var datas = [];
var first = [];
var second = [];
var third = [];

var menuId = 0;
var id = "";
var next = "0";
$(document).ready(function(){
    menuId = getQueryString("menuId");
    id = getQueryString("id");
    next = getQueryString("next");
    queryList2(menuId);
    queryInfo(id);
});

function queryInfo(id){
    $.ajax({
        url : urladdr + "/web/article/info",
        method : "GET",
        data : {
            id:id,
            hit:1,
            menuId:menuId
        },
        success : function(data){
            if(data.code == 0){
                if(data.data.type == 1 || data.data.type == 5){
                    var ext = JSON.parse(data.data.ext);
                    document.getElementById("article_title").innerHTML = data.data.title;
                    document.getElementById("author").style.display = "";
                    document.getElementById("author").innerHTML = "作者:" + ext.authorName;
                    document.getElementById("userName").innerHTML = '编辑人:' +data.data.userName;
                    document.getElementById("time").innerHTML = "发布时间:" + ext.submitTime;
                    document.getElementById("visit").innerHTML = "访问量:" + data.data.hit;
                    document.getElementById("contentInfo").innerHTML = data.data.content;
                    document.getElementById("subtitle").innerHTML = ext.subtitle;
                    document.getElementById("picture").style.display = "none";
                }else {
                    document.getElementById("article_title").innerHTML = data.data.title;
                    document.getElementById("author").style.display = "none";
                    document.getElementById("userName").innerHTML = '作者:' +data.data.userName;
                    document.getElementById("time").innerHTML = "发布时间:" + data.data.addTime;
                    document.getElementById("visit").innerHTML = "访问量:" + data.data.hit;
                    document.getElementById("contentInfo").innerHTML = data.data.content;
                    if(data.data.content=="" || data.data.content == "<br>" || data.data.content == "<p><br></p>"){
                        document.getElementById("picture").style.display = "";
                        document.getElementById("picture").src = imgUrl + data.data.imageUrl;
                    }
                }


                if(data.data.type != 5){
                    if(data.context.prevTitle == null){
                        var prevTitle = "无";
                        document.getElementById("prevText").href = "#";
                    }else {
                        prevTitle = data.context.prevTitle;
                        document.getElementById("prevText").href = "text.html?menuId="+menuId + "&id="+data.context.prevId+"&next="+next;
                    }

                    if(data.context.nextTitle == null){
                        var nextTitle = "无";
                        document.getElementById("nextText").href = "#";
                    }else{
                        nextTitle = data.context.nextTitle;
                        document.getElementById("nextText").href = "text.html?menuId="+menuId + "&id="+data.context.nextId+"&next="+next;
                    }
                }else{
                    prevTitle = "无";
                    document.getElementById("prevText").href = "#";
                    nextTitle = "无";
                    document.getElementById("nextText").href = "#";
                }

                document.getElementById("prevText").innerHTML = "上一篇:"+ prevTitle;
                document.getElementById("prevText").name = data.context.prevId;
                document.getElementById("nextText").innerHTML = "下一篇:"+ nextTitle;
                document.getElementById("nextText").name = data.context.nextId;
            }else if(data.code == 404){
                location.href = "404.html"
            }else{
                modalinfo(data.msg);
            }
        }
    });
}